import $ from '../../../utils/ajax.js';
import util from '../../../utils/util.js';
const app = getApp();
Page({
    data: {
        topContent:{},
        allMonry:'',
        shopList:{
            page:1,
            size:10,
            recordRoleId:'',
            storeName:''
        },
        content:[],
        value:'',
        province:'',
        city:'',
        area:''

    },
    onLoad: function (options) {
        //记得传参
       
        this.setData({
            ['shopList.recordRoleId']: options.storeId
        })
       
    },
    onShow() {
        this.dataList()
        this.contenList()
    },
    goShop({ currentTarget: { dataset: { storeid } } }) {
        console.log(storeid)
        wx.navigateTo({
            url: `/pages/index/shopInformation/shopInformation?storeId=${storeid}`,
        })
    },
    //获取输入框里的内容
    details(e) {
        const value = e.detail.value;
        this.setData({
            value: value
        })
    },
    //搜索
    search() {
        console.log(this.data.value, "11111")
        this.setData({
            ['shopList.storeName']: this.data.value,
            ['shopList.page']: 1
        }, () => {
            this.contenList()
        })
    },
    //下拉刷新
    onPullDownRefresh() {
        this.dataList()
        this.setData({
            value: '',
            ['shopList.page']: 1,
            ['shopList.storeName']:''

        }, () => {
            this.contenList()
        })
        wx.stopPullDownRefresh()
    },
    // agentnew/getRoleInfoByToken
    //上拉加载
    onReachBottom() {

        this.data.shopList.page++ ,
            this.contenList()
    },
    dataList() {
       
        $.p(app.wxApp.url + 'agentincome/getAgentRoleAllStoreCommissionUp', { 
            recordRoleId: this.data.shopList.recordRoleId
        }, app.onStrart, (res) => {
            console.log(res.data.amountAll)
            this.setData({
                topContent: res.data.agentInfo,
                allMonry: res.data.amountAll,
                province: res.data.province,
                city: res.data.city,
                area: res.data.area

            })
            console.log(this.data.topContent,"2312131231")
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },
    contenList() {
        $.p(app.wxApp.url + 'agentincome/getAgentRoleAllStoreCommissionDown', { ...this.data.shopList}, app.onStrart, (res) =>           {
                let data = this.data.content;
                if (res.data.page === 1) {
                    data = res.data.list
                } else {
                    res.data.list.map((item) => {
                        data.push({
                            ...item
                        })
                    })
                }
                this.setData({
                    content: data
                })
            console.log(res.data)
                app.onShop();
            }, (res) => {
                util.showToast(res.data)
            })
        }
})